template<class Ring>
struct Class {
  Ring X, Y;

  Class (const Ring& len) { X = len; Y = len; }
  Class (const Ring& x, const Ring& y) { X = x; Y = y; }
  Class (const Ring* arr) { 
    for (int i = 0; i < 2; ++i) 
      *this[i] = arr[i]; 
  }
  operator const Ring* () const { return &X; }
  operator Ring* () { return &X; }
  // simple operators
  inline Type operator- () const {
    return Type(-X, -Y); 
  }
  inline Type operator+ (const Type& other) const {
    return Type(X + other.X, Y + other.Y);
  }
  inline Type operator- (const Type& other) const {
    return Type(X - other.X, Y - other.Y);
  }
  inline Type operator* (const Type& other) const {
    return Type(X * other.X, Y * other.Y);
  }
  inline Type& operator+= (const Type& other) { 
    X += other.X;
    Y += other.Y;
    return *this;
  }
  inline Type& operator-= (const Type& other) { 
    X -= other.X; 
    Y -= other.Y; 
    return *this; 
  }
  inline Type& operator*= (const Type& other) { 
    X *= other.X; 
    Y *= other.Y; 
    return *this; 
  }
  // dot product
  inline Ring operator^ (const Type& other) const { 
    return X*other.X + Y*other.Y; 
  }
  // square of length
  inline Ring QLen() const { 
    return X*X + Y*Y; 
  }

#ifdef VECTOR
  typedef Ring Field;
  template<class OtherRing> Class (const ModClass<OtherRing>& m) : X(m.X), Y(m.Y) {}
  // length
  inline Field Len() const { return sqrt(X*X + Y*Y); }
  inline Field operator~() const { return sqrt(X*X + Y*Y); }
  inline Type& Normalize() {
    Field len = Len();
    if (zero(len))
      X = Y = 0;
    else {
      X /= len;
      Y /= len;
    }
    return *this;
  }
  inline Type Norm() {
    Field len = Len();
    if (zero(len))
      return Type(0, 0, 0);
    else
      return Type(X/len, Y/len);
  }
#endif
};

template<class Field>
Field QDist(const Class<Field>& v, const Class<Field>& u) {
  return (v - u).QLen();
}

#ifdef VECTOR
template<class Field>
Field Dist(const Class<Field>& v, const Class<Field>& u) {
  return ~(v - u);
}
#endif
